package com.mio.web.util;

import javax.servlet.http.HttpSession;

import org.apache.commons.fileupload.ProgressListener;

import com.mio.web.common.ProcessInfo;

public class FileUploadListener implements ProgressListener {
	private HttpSession session;

	public FileUploadListener(HttpSession session) {
		this.session = session;
	}

	// pBytesRead 已经上传的大小
	// pContentLength 文件总大小
	public void update(long pBytesRead, long pContentLength, int pItems) {
		System.out.println(( (int) Math.round(100.00 * pBytesRead / pContentLength)));
    	ProcessInfo pri = new ProcessInfo();
        pri.itemNum = pItems;  
        pri.readSize = pBytesRead;  
        pri.totalSize = pContentLength;  
        pri.show = pBytesRead/1024/8+"/"+pContentLength/1024/8+"KB";  
        pri.rate = Math.round(new Float(pBytesRead) / new Float(pContentLength)*100);
		//session.setAttribute("progress",  (int) Math.round(100.00 * pBytesRead / pContentLength));
        session.setAttribute("progress",  pri);
	}
}
